#include "stdafx.h"
#include "Shape.h"

SShape * SPoint::Clone() const
{
	return new SPoint(x, y);
}
SShape * SSize::Clone() const
{
	return new SSize(cx, cy);
}
SIZE SSize::ToSIZE() const
{
	SIZE s;
	s.cx = cx;
	s.cy = cy;
	return s;
}
SShape * SLine::Clone() const
{
	return new SLine(cx, cy);
}
SShape * SRect::Clone() const
{
	return new SRect(left, top, right, bottom);
}

RECT SRect::ToRECT() const
{
	RECT rc;
	rc.left = left;
	rc.right = right;
	rc.top = top;
	rc.bottom = bottom;
	return rc;
}

SPoint SRect::CenterPoint() const
{
	SPoint pt;
	pt.x = left + Width()/2;
	pt.y = top + Height()/2;
	return pt;
}

bool SRect::operator==(const SRect rc)
{
	return left == rc.left && top == rc.top && right == rc.right && bottom == rc.bottom;
}

bool SRect::operator==(const RECT rc)
{
	return left == rc.left && top == rc.top && right == rc.right && bottom == rc.bottom;
}

bool SRect::operator!=(const SRect rc)
{
	return left != rc.left || top != rc.top || right != rc.right || bottom != rc.bottom;
}

bool SRect::operator!=(const RECT rc)
{
	return left != rc.left || top != rc.top || right != rc.right || bottom != rc.bottom;
}

SRect SRect::operator+(const int nSize)
{
	SRect rc = *this;
	rc.left -= nSize;
	rc.top -= nSize;
	rc.right += nSize;
	rc.bottom += nSize;

	if (rc.left <= 0 || rc.top <= 0 || rc.right <= 0 || rc.bottom <= 0)
	{
		return *this;
	}
	else
	{
		return rc;
	}
}

SRect SRect::operator-(const int nSize)
{
	SRect rc = *this;
	rc.left += nSize;
	rc.top += nSize;
	rc.right -= nSize;
	rc.bottom -= nSize;

	if (rc.left <= 0 || rc.top <= 0 || rc.right <= 0 || rc.bottom <= 0)
	{
		return *this;
	}
	else
	{
		return rc;
	}
}